//byd 前几天出 8424 现在就出 8425 是吧
//byd 为什么要 7s 变成 4s
//素质较差蛤
#include<bits/stdc++.h>
using namespace std;
// #define int long long
const int maxn=8e3+5,INF=1e9;
int p[maxn],n,f[maxn][4],g[maxn][4];
int cnt=0;
#define min(x,y) (x<y?x:y)
namespace ZKW{
    int t[maxn<<2],M;
    inline void build(int n){
        for(M=1;M<=n+1;M<<=1);
        for(int i=M+1;i<=M+n;++i) t[i]=INF;
        for(int i=M;i;i--) t[i]=INF;
    }
    inline void add(int x,int v){
        for(x+=M;x;x>>=1) t[x]=min(t[x],v);
    }
    inline int ask(int l,int r){
        int ans=INF;
        for(l+=M-1,r+=M+1;l^r^1;l>>=1,r>>=1){
            if(~l&1) ans=min(ans,t[l^1]);
            if(r&1) ans=min(ans,t[r^1]);
        }
        return ans;
    }
}
using namespace ZKW;
struct pt{int x,y,v,id;};
vector<pt> P;
void rev(){for(auto &u:P)swap(u.x,u.y);}
void revx(){for(auto &u:P)u.x=n-u.x+1;}
void revy(){for(auto &u:P)u.y=n-u.y+1;}
vector<pt> G;
inline bool cmp(pt a,pt b){return (a.y-a.x==b.y-b.x&&(a.y==b.y?a.id>b.id:a.y>b.y))||(a.y-a.x<b.y-b.x);}
inline void solve(int tp){
	G=P;
	build(n);
	for(auto &u:G)u.v+=u.x;
	sort(G.begin(),G.end(),cmp);
	int M=INF,B=n/4;
	for(auto u:G){
		if(u.id==-1)add(u.y,u.v);
		else g[u.id][tp]=min(g[u.id][tp],ask(u.y+1,n)-u.x);
	}
}
inline bool pd(int x,int tp){
	int X=x;
	if(tp==0||tp==1)X+=f[x][tp];
	else X-=f[x][tp];
	int Y=p[x];
	if(tp==0||tp==3)Y+=f[x][tp];
	else Y-=f[x][tp];
	if(max(X,Y)>n||min(X,Y)<=0)return 0;
	return 1;
}
signed main(){
	freopen("build.in","r",stdin);
	freopen("build.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>p[i];
	int t=1;
	while(1){
		for(int i=1;i<=n;i++)
			for(int j=0;j<4;j++)g[i][j]=1e9;
		P.clear();
		for(int i=1;i<=n;i++){
			if(pd(i,0))P.push_back({i,p[i],f[i][0],-1});
			if(pd(i,1))P.push_back({i,p[i]-f[i][1],f[i][1],-1});
			if(pd(i,2))P.push_back({i-f[i][2],p[i]-f[i][2],f[i][2],-1});
			if(pd(i,3))P.push_back({i-f[i][3],p[i],f[i][3],-1});
			P.push_back({i,p[i],-1,i});
		}
		solve(0);
		rev();
		solve(0);
		
		P.clear();
		for(int i=1;i<=n;i++){
			if(pd(i,0))P.push_back({i+f[i][0],p[i],f[i][0],-1});
			if(pd(i,1))P.push_back({i+f[i][1],p[i]-f[i][1],f[i][1],-1});
			if(pd(i,2))P.push_back({i,p[i]-f[i][2],f[i][2],-1});
			if(pd(i,3))P.push_back({i,p[i],f[i][3],-1});
			P.push_back({i,p[i],-1,i});
		}
		revx();
		solve(3);
		rev();
		solve(3);
		
		P.clear();
		for(int i=1;i<=n;i++){
			if(pd(i,0))P.push_back({i,p[i]+f[i][0],f[i][0],-1});
			if(pd(i,1))P.push_back({i,p[i],f[i][1],-1});
			if(pd(i,2))P.push_back({i-f[i][2],p[i],f[i][2],-1});
			if(pd(i,3))P.push_back({i-f[i][3],p[i]+f[i][3],f[i][3],-1});
			P.push_back({i,p[i],-1,i});
		}
		revy();
		solve(1);
		rev();
		solve(1);
		
		P.clear();
		for(int i=1;i<=n;i++){
			if(pd(i,0))P.push_back({i+f[i][0],p[i]+f[i][0],f[i][0],-1});
			if(pd(i,1))P.push_back({i+f[i][1],p[i],f[i][1],-1});
			if(pd(i,2))P.push_back({i,p[i],f[i][2],-1});
			if(pd(i,3))P.push_back({i,p[i]+f[i][3],f[i][3],-1});
			P.push_back({i,p[i],-1,i});
		}
		revx();revy();
		solve(2);
		rev();
		solve(2);
		
		bool flg=0;
		for(int i=1;i<=n;i++)
			for(int j=0;j<4;j++){
				f[i][j]=g[i][j];
				if(pd(i,j))flg=1;
			}
		if(!flg)break;
		++t;
	}
	cout<<(n-t)<<endl;
	// cerr<<"cnt="<<cnt<<endl; 
	return 0;
}